import numpy as np
from numba import jit
# C deploy for fast get brt


@jit(nopython=True, cache=True)
def _get_brtJIT(img, map, kernel):
    r, c, _ = map.shape
    brt = np.zeros(map.shape[0:-1])
    kernel_size = int(kernel.shape[0] / 2)

    for ridx in range(r):
        for cidx in range(c):
            y, x = int(map[ridx, cidx, 0]), int(map[ridx, cidx, 1])
            if x == 0 or y == 0:
                brt[ridx, cidx] = 0
            else:
                region = img[x - kernel_size:x + kernel_size + 1, y - kernel_size:y + kernel_size + 1]
                brt[ridx, cidx] = (np.mean(region * kernel))

    return brt
